package com.swfpeep.resource
{
	import com.swfpeep.SWFPeep;
	import com.swfpeep.data.SWFFileInfo;
	import com.swfpeep.events.SWFPeepEvent;
	import com.swfpeep.ui.SWFResourcePanel;
	import com.swfwire.decompiler.AsyncSWFReader;
	import com.swfwire.decompiler.SWFByteArray;
	
	import flash.events.Event;
	
	import mx.controls.Alert;

	public class SWFResourceManager
	{
		static private var _INSTANCE:SWFResourceManager;
		
		static public function getInstance(ui:SWFResourcePanel = null):SWFResourceManager
		{
			if(_INSTANCE == null)
				_INSTANCE = new SWFResourceManager(ui);
			
			return _INSTANCE;
		}
		
		protected var m_ui:SWFResourcePanel;
		protected var m_createSWFReadResult:CreateSWFReadResult;
		
		public function SWFResourceManager(ui:SWFResourcePanel)
		{
			this.m_ui = ui;	
			this.initThis();
		}
		
		protected function initThis():void
		{
			SWFPeep.APP.addEventListener(SWFPeepEvent.ON_PARSE_SWF,onParseSwf);
			m_createSWFReadResult = new CreateSWFReadResult(SWFPeep.PROGRESS_BAR);
			m_createSWFReadResult.addEventListener(Event.COMPLETE,onResultCreated);
		}
		
		protected function onParseSwf(event:SWFPeepEvent):void
		{
			var swfFileInfo:SWFFileInfo = SWFPeep.APP.currentSWFFileInfo;
			if(swfFileInfo != null && swfFileInfo.bytes != null)
			{
				if(swfFileInfo.readResult == null)
				{
					///打开日志记录
					SWFPeep.LOG_PANEL.open();
					///读取SWF文件
					m_createSWFReadResult.process(swfFileInfo);
					
				} 
				else
					onResultCreated(null);
			}
			else
				Alert.show("没有找到SWF信息","警告");
			
		}
		
		protected function onResultCreated(event:Event):void
		{
			
		}
	}
}